#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

int main()
{
    int num = 0;
    scanf("%d", &num);
    int x[1000] = { 0 };
    int i = 2;
    x[0] = 1;
    x[1] = 1;
    if (num < 2)
        i = 0;
    else
    {
        while (1)
        {
            x[i] = x[i - 1] + x[i - 2];
            if (x[i] >= num)
                break;
            i++;
        }
    }
    int j = 0;
    while (1)
    {
        if (num - j == x[i - 1])
        {
            printf("%d", j);
            break;
        }
        else if (num + j == x[i])
        {
            printf("%d", j);
            break;
        }
        j++;
    }
    return 0;
}